//
//  StatusCellBottomView.swift
//  0110-weibo
//
//  Created by 鲍志刚 on 16/1/18.
//  Copyright © 2016年 zhongye. All rights reserved.
//

import UIKit
import SnapKit

class StatusCellBottomView: UIView {


    //自定义入口
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //设置视图
    private func setupUI(){
        
        backgroundColor = UIColor.whiteColor()
        
        //添加子控件
        addSubview(retweedBtn)
        addSubview(commentBtn)
        addSubview(likeBtn)
  
        //三等分一个视图
        //1.左右都应该设置约束条件
        //2.设置宽度相等
        //设置约束
       retweedBtn.snp_makeConstraints { (make) -> Void in
        make.left.top.bottom.equalTo(self)
        }
        
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(self)
            make.left.equalTo(retweedBtn.snp_right)
            make.width.equalTo(retweedBtn.snp_width)
        }
        
        likeBtn.snp_makeConstraints { (make) -> Void in
            make.bottom.top.equalTo(self)
            make.right.equalTo(self.snp_right)
            make.left.equalTo(commentBtn.snp_right)
            make.width.equalTo(commentBtn.snp_width)
        }
        
        
        //添加按钮之间的imageview
        let sepView1 = lineView()
        
        let sepView2 = lineView()
        
        addSubview(sepView1)
        addSubview(sepView2)
        
        //设置约束
        let w : CGFloat = 0.5
        let scale : CGFloat = 0.4
        
        sepView1.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(retweedBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(scale)
            make.width.equalTo(w)
        }
        
        sepView2.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            make.height.equalTo(self.snp_height).multipliedBy(scale)
            make.width.equalTo(w)
        }
        
        
        //添加点击事件
        commentBtn.addTarget(self, action: "commentBtnDidClick", forControlEvents: .TouchUpInside)
        
        
    }
    
    @objc private func commentBtnDidClick(){
    
//        print("commentBtnDidClick")
        let temp = TempViewController()
        //在页面跳转中 使用的频率非常高 可以代替绝大部分的页面跳转中使用协议代理 /  block
        //在push之前设置 隐藏底部 tabbar
        
        temp.hidesBottomBarWhenPushed = true
        
        navController()?.pushViewController(temp, animated: true)
        
    
    }
    
    private func lineView() -> UIView {
        
        let v = UIView()
        
        v.backgroundColor = UIColor.lightGrayColor()
            return v
    }
    
    
    
    //懒加载子视图
    //转发微博按钮
    private lazy var retweedBtn: UIButton = UIButton(title: "转发", fontSize: 10, color: UIColor.darkGrayColor(), backImageName: nil,imageName: "timeline_icon_retweet")
    
    //评论
    private lazy var commentBtn: UIButton = UIButton(title: "评论", fontSize: 10, color: UIColor.darkGrayColor(), backImageName: nil, imageName: "timeline_icon_comment")
    
    //点赞
    private lazy var likeBtn: UIButton = UIButton(title: "点赞", fontSize: 10, color: UIColor.darkGrayColor(), backImageName: nil, imageName: "timeline_icon_unlike")

}
